var datatable;// 定义一个全局的dataTable
var beginDateTemp;
var endDateTemp;
var dateTypeTemp;
var failureTypeList;
var queryCond;
var failureDetailQueryCond;
var s1mme;
var s11;
var s2a;
var gxgy;
var s5s8;
var sta;
var s6a;
var interfaceType;

$(function() {
	initInfo();
	getList();
});

function getList() {

	$("#table tbody tr").remove();
	if (datatable == undefined || datatable == "undefined" || datatable == null) {
	} else {
		datatable.fnDestroy();
	}
	datatable = $('#table')
			.dataTable(
					{
						"bPaginate" : false, // 翻页功能
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"bSort" : true, // 排序功能
						"bInfo" : false,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						"fnDrawCallback" : function(oSettings) {
						},
						// "sPaginationType": "full_numbers",//显示分页的样式
						// 还有simple_numbers等
						"sScrollX" : "97%",
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "没有记录",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "前一页",
								"sNext" : "后一页",
								"sLast" : "尾页"
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
						"sAjaxSource" : "../../kpi/interfaceFailureLink/getList",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$.ajax({
										"type" : "post",
										"contentType" : "application/x-www-form-urlencoded",
										"url" : sSource,
										"dataType" : "json",
										"data" : {
											"aoData" : JSON.stringify(aoData),
											"dateType" : $("#param_dateType").val(),
											"interfaceType" : $("#param_interfaceType").val(),
											"beginDate" : $("#param_paramDate").val(),
											"endDate" : $("#param_paramDate").val(),
											"signalType" : $("#param_signalType").val(),
											"type" : $("#type").val(),
											"tac_status" : $("#tac_status").val(),
											"eNodeBID_status" : $("#eNodeBID_status").val(),
											"village_status" : $("#village_status").val(),
											"failureTypeInfo" : $("#failureTypeInfo").val(),
											"mme_name" : $("#mme_name").val(),
											"city_code" : $("#city_code").val(),
											"tai" : $("#tai").val(),
											"enodeb_id" : $("#enodeb_id").val(),
											"enodeb_name" : $("#enodeb_name").val(),
											"cell_name" : $("#cell_name").val(),
											"group_id" : $("#group_id").val(),
											"msisdn" : $("#msisdn").val(),
											"user_terminal" : $("#user_terminal").val(),
											"terminal_brand" : $("#terminal_brand").val(),
											"apn_name" : $("#apn_name").val(),
											"jspType" : $("#jspType").val()
										}, // 以json格式传递
										"success" : function(resp) {
											beginDateTemp = resp.beginDate;
											endDateTemp = resp.endDate;
											dateTypeTemp = resp.dateType;
											failureTypeList = resp.failureTypeList;
											queryCond = resp.queryCond;
											failureDetailQueryCond = resp.failureDetailQueryCond;
											fnCallback(resp.allData);
										}
									});
						},
						columns : [ {
							data : "report_date"
						}, {
							data : "interface"
						}, {
							data : "signal_process"
						}, {
							data : "failure_type"
						}, {
							data : "failure_type"
						}, {
							data : "failure_count"
						}, {
							data : "failure_rate"
						} ],
						aoColumnDefs : [
								{
									"render" : function(val, type, row) {
										return interfaceType[val] == undefined ? "" : interfaceType[val];
									},
									"targets" : 1
								},
								{

									"render" : function(val, type, row) {
										var data = interfaceType[row.interface] == undefined ? "" : interfaceType[row.interface];
										if(data == 'S1-MME'){
											return s1mme[val];
										}else if(data == 'S6a'){
											return s6a[val];
										}else if(data == 'S11'){
											return s11[val];
										}else if(data == 'S2a'){
											return s2a[val];
										}else if(data == 'Gx' || data == 'Gy'){
											return gxgy[val];
										}else if(data == 'STa'){
											return sta[val];
										}else if(data == 'S5/S8'){
											return s5s8[val];
										}else{
											return "";
										}
									},
									"targets" : 2
								},
								{

									"render" : function(data, type, full) {
										var url = "<a href='#' onclick=\"failureTypeDetail('"
												+ full['interface']
												+ "','"
												+ full.signal_process
												+ "','"
												+ full.failure_type
												+ "')\"  >"
												+ (data == null ? "" : data) + "</a>";
										return url;
									},
									"targets" : 3
								},
								{
									"render" : function(data, type, full) {
										  var failureType=full.failure_type;
										  var failureTypeName=''; 
										  for(var j=0;j<failureTypeList.length;j++){
											  var tempValue=failureTypeList[j].value;
											  if(tempValue==failureType){
												  failureTypeName=failureTypeList[j].label;
												  break; 
											  } 
										  } 
										  return failureTypeName;
									},
									"targets" : 4
								},
								{
									"render" : function(data, type, full) {
										var url = "";

										url = "<a href='#' onclick=\"failureCountDetail('"
												+ full['interface']
												+ "','"
												+ full.signal_process
												+ "','"
												+ full.failure_type
												+ "')\"  >"
												+ full.failure_count + "</a>";
										return url;
									},
									"targets" : 5
								} ]

					});

}
function test(){
	$("#table thead").hide();
}
function failureCountDetail(interfaceType,signalType,failureType){
	var failureTypeInfo = $("#failureTypeInfo").val();
	var jspType =  $("#jspType").val();
	var url="/kpi/userFailureLink/index?beginDate="+beginDateTemp.trim()+"&endDate="+endDateTemp.trim()
	+"&interfaceType="+interfaceType.trim()+"&procedureType="+signalType.trim()+"&failureType="+failureType.trim()
	+"&dateType="+dateTypeTemp.trim()+"&failureTypeInfo="+failureTypeInfo+"&jspType="+jspType+"&queryCond="+queryCond+"&failureDetailQueryCond="+failureDetailQueryCond;
	linkTab("失败用户",url);
}
function failureTypeDetail(interfaceType,signalType,failureType){
	var url="/kpi/expertDiagnosis/index?Product_type="+interfaceType.trim()+"&Error_code="+failureType.trim()+"&Type=1&Interface="+signalType;
	linkTab("专家诊断",url);
}

function initInfo(){
	s1mme = {'1' : 'attach','2' : 'Sevice Request','3' : 'Extended Service Request（CSFB）', '4' : 'Paging' , '5' : 'TAU',
			 '6' : 'Detach','7' : 'PDN connectivity','8' : 'PDN disconnection', '9' : 'EPS bearer resource allocation' , '10' : 'EPS bearer resource modify',
			 '11' : 'EPS bearer context deactivation','12' : 'EPS bearer context modification','13' : 'Dedicated EPS bearer context activation', '14' : 'Path Switch' , '15' : 'S1切出',
		     '16' : 'S1切入','17' : 'UE context setup','18' : 'UE context modification', '19' : 'UE context release' , '20' : 'E-RAB release',
		     '28' : 'Identity Acquisition','29' : 'Authenticaiton','30' : 'Security Mode Command', '100' : 'PagingResult'};
	s11 = {'1' : 'Create Session' , '2' : 'Modify Bearer' , '3' : 'Delete Session','4' : 'Modify Bearer Command', '5' : 'Delete Bearer Command',
		   '6' : 'Bearer Resource Command' , '7' : 'Create Bearer ' , '8' : 'Update Bearer','9' : 'Delete Bearer', '10' : 'Release Access Bearers',
		   '11' : 'Modify Access Bearers' , '14' : 'Change Notification' , '15' : 'Downlink Data Notification','20' : 'PGW Downlink Triggering Notification', '21' : 'Identification Request',
		   '22' : 'Context Request' , '23' : 'Forward Relocation Request' , '24' : 'Forward Relocation Complete Notification','25' : 'Forward Access Context Notification', '26' : 'Relocation Cancel Request',
		   '28' : 'Suspend Notification' , '29' : 'Create Forwarding Tunnel' , '30' : 'Resume Notification','31' : 'Create Indirect Data Forwarding Tunnel', '32' : 'Delete Indirect Data Forwarding Tunnel'};
	s2a = {'1' : '初始附着' , '2' : '切换附着' , '3' : '更新' , '4' : '去附着'};
	gxgy = {'1' : 'CCR-I' , '2' : 'CCR-U' , '3' : 'CCR-T' , '4' : 'RAR'};
	s5s8 = {'2' : 'Modify Bearer' , '3' : 'Create Session' , '5' : 'Delete Session' , '6' : 'Change Notification' , '7' : 'Resume Notification',
			'8' : 'Modify Bearer Command' , '10' : 'Delete Bearer Command' , '12' : 'Bearer Resource Command' , 
			'16' : 'Create Bearer' , '17' : 'Update Bearer' , '18' : 'Delete Bearer' , '20' : 'Suspend Notification'};
	sta = {'1' : '接入鉴权和授权' , '2' : '重鉴权和重授权' , '3' : '去附着'};
	s6a = {'1' : 'Update Location' , '2' : 'Cancel Location' , '3' : 'Purge UE' , '4' : 'Insert Subscriber Data' , '5' : 'Delete Subscriber Data' , '6' : 'Authentication Information'};
	interfaceType = {'2' : 'S1-MME' , '3' : 'S6a' , '4' : 'S11' , '7' : 'S2a' , '9' : 'Gx' , '10' : 'Gy' , '8' : 'STa' , '6' : 'S5/S8'};
}
